package controller;

import entity.T163;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author wuchao66
 * @Date 2023/5/23 10:25
 * @PackageName:${PACKAGE_NAME}
 * @ClassName: ${NAME}
 * @Description: TODO
 * @Param
 * @Version 1.0
 */
@WebServlet(name = "ServletTest1",urlPatterns = "/ServletTest1")
public class ServletTest1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();//文件流

        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();//文件流
        String name=request.getParameter("name");
        out.print(name);
        if(name.equals("1")){
            request.setAttribute("bl","变量");
            T163 t163 = new T163();
            t163.name="对象";
            request.setAttribute("dx",t163);
            List<T163> t163s = new ArrayList<>();
            t163s.add(t163);
            T163 t164 = new T163();
            t164.name="对象4";
            t163s.add(t164);
            request.setAttribute("list",t163s);
            Map<String,T163> map=new HashMap<>();
            map.put("map",t163);
            Date date = new Date();

            request.setAttribute("date",date);
            request.setAttribute("map",map);
            request.getRequestDispatcher("/test/testser.jsp?ip=转发").forward(request,response);
        }else{
            response.sendRedirect(request.getContextPath()+"/test/testser.jsp?ip=33");
        }
        out.flush();
        out.close();
    }
}
